package udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpServer {

	public static void main(String[] args) throws Exception{
		//byte[] buf=new byte[1024];
		DatagramPacket packet=new DatagramPacket(new byte[1024], 1024);
		
		DatagramSocket socket=new DatagramSocket(8002);
		socket.receive(packet);
		int len=packet.getLength();
		byte[] data=packet.getData();
		String s=new String(packet.getData(),0,packet.getLength());
		System.out.println(s);
		
		
		//confirm 
		InetAddress address=packet.getAddress();
		int port=packet.getPort();
		DatagramPacket p1=new DatagramPacket("ack".getBytes(), 0, 3, address, port);
		socket.send(p1);
		
		
		socket.close();
		
		
	}

}






